Fix regression with path overrides
authorAlex Crichton <alex@alexcrichton.com>
Fri, 4 Nov 2016 00:00:13 +0000 (17:00 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 15 Nov 2016 19:51:15 +0000 (11:51 -0800)
If an override points to a path dependency then that's not locked, so we're
missing information for that, but it's already warned about, so no need to
worry.

src/cargo/core/registry.rs
tests/overrides.rs

index 037b87a8b62c34a8ff3b1eb4991b1d4dc6d99837..a798a49a5044faba36a0a182f9eaa4d1b1e27305 100644 (file)
@@ -291,9 +291,13 @@ impl<'cfg> PackageRegistry<'cfg> {
                          override_summary: &Summary,
                          real_summary: &Summary) -> CargoResult<()> {
         let real = real_summary.package_id();
-        let map = self.locked.get(real.source_id()).chain_error(|| {
-            human(format!("failed to find lock source of {}", real))
-        })?;
+        // If we don't have a locked variant then things are going quite wrong
+        // at this point, but we've already emitted a warning, so don't worry
+        // about it.
+        let map = match self.locked.get(real.source_id()) {
+            Some(map) => map,
+            None => return Ok(()),
+        };
         let list = map.get(real.name()).chain_error(|| {
             human(format!("failed to find lock name of {}", real))
         })?;
index ba17e0f3253b72a04d6cdc4c7877e8aec7216a37..2ba54fbc271802a90d8b519545ee8a9f55235510 100644 (file)
@@ -925,3 +925,91 @@ fn overriding_nonexistent_no_spurious() {
 [FINISHED] [..]
 ").with_stdout(""));
 }
+
+#[test]
+fn override_to_path_dep() {
+    Package::new("foo", "0.1.0").dep("bar", "0.1").publish();
+    Package::new("bar", "0.1.0").publish();
+
+    let p = project("local")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "local"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.1.0"
+        "#)
+        .file("src/lib.rs", "")
+        .file("foo/Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            bar = { path = "bar" }
+        "#)
+        .file("foo/src/lib.rs", "")
+        .file("foo/bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("foo/bar/src/lib.rs", "")
+        .file(".cargo/config", r#"
+            paths = ["foo"]
+        "#);
+
+    assert_that(p.cargo_process("build"),
+                execs().with_status(0));
+}
+
+#[test]
+fn replace_to_path_dep() {
+    Package::new("foo", "0.1.0").dep("bar", "0.1").publish();
+    Package::new("bar", "0.1.0").publish();
+
+    let p = project("local")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "local"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.1.0"
+
+            [replace]
+            "foo:0.1.0" = { path = "foo" }
+        "#)
+        .file("src/lib.rs", "extern crate foo;")
+        .file("foo/Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            bar = { path = "bar" }
+        "#)
+        .file("foo/src/lib.rs", "
+            extern crate bar;
+
+            pub fn foo() {
+                bar::bar();
+            }
+        ")
+        .file("foo/bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("foo/bar/src/lib.rs", "pub fn bar() {}");
+
+    assert_that(p.cargo_process("build"),
+                execs().with_status(0));
+}